package progress

import (
	"kuafu/progress/log"
	"os"
)

type Progress struct {
}

func (*Progress) Start() {

	pidManager := PidManager{}
	pidManager.CreatePid()
}

func (*Progress) Stop() {

	pidManager := PidManager{}
	pid := pidManager.GetPid()
	if pid > 0 {
		proc, errProc := os.FindProcess(pid)
		if errProc != nil {
			log.Log.Errorf("stop 进程失败 %s", errProc)
			pidManager.RemovePid()
			return
		}

		if proc != nil {
			errKill := proc.Kill()
			if errKill != nil {
				log.Log.Errorf("stop kill进程失败 %s", errKill)
				pidManager.RemovePid()
				return
			}
		}
	}
	pidManager.RemovePid()

}
